package com.bsoft.gol.hcb.controller;



import com.bsoft.gol.hcb.service.prescriptionCirculation.DrugOrdersService;
import hcn.util.BaseResponse;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pcn.bean.operationPlatform.request.RecipeStatusNoticeReq;

import javax.validation.Valid;


/**
 * @author tongtp
 * @version v0.1
 * @className PrescriptionCirculationController
 * @description 处方流转
 * @create 2019-08-24 20:31
 **/
@Controller
@RequestMapping(value = "/open/prescription/")
public class PrescriptionCirculationController {

    private static Logger logger = LoggerFactory.getLogger(PrescriptionCirculationController.class);
    @Autowired
    private DrugOrdersService drugOrderService;


    /**
     * @Author:FangZhiyi
     * @Description 处方流转平台订单状态更新通知
     * @Params  [recipeStatusNoticeReq, bindingResult]
     * @Return  com.bsoft.hessian.entity.BaseResponse
     * @Data Created in 2020/8/5 21:06
     * @Moddified By:
     */
    @RequestMapping("/recipeStatusNotice")
    @ResponseBody
    public BaseResponse recipeStatusNotice(@RequestBody @Valid RecipeStatusNoticeReq recipeStatusNoticeReq, BindingResult bindingResult) {
        logger.info("recipeStatusNotice request : {}", recipeStatusNoticeReq);
        BaseResponse resp = new BaseResponse();
        if (bindingResult.hasErrors()) {
            resp.setCode(ResultCode.ERROR);
            resp.setMessage(bindingResult.getFieldError().getDefaultMessage());
            return resp;
        }
        return drugOrderService.recipeStatusNotice(recipeStatusNoticeReq);
    }

    /**
     * @Author:FangZhiyi
     * @Description 按订单号查询物流
     * @Params  [recipeStatusNoticeReq, bindingResult]
     * @Return  com.bsoft.hessian.entity.BaseResponse
     * @Data Created in 2020/8/5 21:05
     * @Moddified By:
     */
    @RequestMapping("/queryLogistics")
    @ResponseBody
    public BaseResponse queryLogistics(@RequestBody @Valid RecipeStatusNoticeReq recipeStatusNoticeReq, BindingResult bindingResult) {
        logger.info("queryLogistics request : {}", recipeStatusNoticeReq);
        BaseResponse resp = new BaseResponse();
        if (bindingResult.hasErrors()) {
            resp.setCode(ResultCode.ERROR);
            resp.setMessage(bindingResult.getFieldError().getDefaultMessage());
            return resp;
        }
        return drugOrderService.queryLogistics(recipeStatusNoticeReq.getOrderNo());
    }
}
